
/*
===============================================================================
                    EntitySpaces Studio by EntitySpaces, LLC
             Persistence Layer and Business Objects for Microsoft .NET
             EntitySpaces(TM) is a legal trademark of EntitySpaces, LLC
                          http://www.entityspaces.net
===============================================================================
EntitySpaces Version : 2012.1.0930.0
EntitySpaces Driver  : SQL
Date Generated       : 3/29/2013 2:25:55 PM
===============================================================================
*/

using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Linq;
using System.Data;
using System.ComponentModel;
using System.Xml.Serialization;
using System.Runtime.Serialization;

using EntitySpaces.Core;
using EntitySpaces.Interfaces;
using EntitySpaces.DynamicQuery;



namespace DNNspot.LiveChat.DataModel
{
	/// <summary>
	/// Encapsulates the 'DNNspot_LiveChat_Categories' table
	/// </summary>

    [DebuggerDisplay("Data = {Debug}")]
	[Serializable]
	[DataContract]
	[KnownType(typeof(Category))]	
	[XmlType("Category")]
	public partial class Category : esCategory
	{	
		[DebuggerBrowsable(DebuggerBrowsableState.RootHidden | DebuggerBrowsableState.Never)]
		protected override esEntityDebuggerView[] Debug
		{
			get { return base.Debug; }
		}

		override public esEntity CreateInstance()
		{
			return new Category();
		}
		
		#region Static Quick Access Methods
		static public void Delete(System.Int32 categoryId)
		{
			var obj = new Category();
			obj.CategoryId = categoryId;
			obj.AcceptChanges();
			obj.MarkAsDeleted();
			obj.Save();
		}

	    static public void Delete(System.Int32 categoryId, esSqlAccessType sqlAccessType)
		{
			var obj = new Category();
			obj.CategoryId = categoryId;
			obj.AcceptChanges();
			obj.MarkAsDeleted();
			obj.Save(sqlAccessType);
		}
		#endregion

		
					
		
	
	}



    [DebuggerDisplay("Count = {Count}")]
	[Serializable]
	[CollectionDataContract]
	[XmlType("CategoryCollection")]
	public partial class CategoryCollection : esCategoryCollection, IEnumerable<Category>
	{
		public Category FindByPrimaryKey(System.Int32 categoryId)
		{
			return this.SingleOrDefault(e => e.CategoryId == categoryId);
		}

		
		
		#region WCF Service Class
		
		[DataContract]
		[KnownType(typeof(Category))]
		public class CategoryCollectionWCFPacket : esCollectionWCFPacket<CategoryCollection>
		{
			public static implicit operator CategoryCollection(CategoryCollectionWCFPacket packet)
			{
				return packet.Collection;
			}

			public static implicit operator CategoryCollectionWCFPacket(CategoryCollection collection)
			{
				return new CategoryCollectionWCFPacket() { Collection = collection };
			}
		}
		
		#endregion
		
				
	}



    [DebuggerDisplay("Query = {Parse()}")]
	[Serializable]	
	public partial class CategoryQuery : esCategoryQuery
	{
		public CategoryQuery(string joinAlias)
		{
			this.es.JoinAlias = joinAlias;
		}	

		override protected string GetQueryName()
		{
			return "CategoryQuery";
		}
		
					
	
		#region Explicit Casts
		
		public static explicit operator string(CategoryQuery query)
		{
			return CategoryQuery.SerializeHelper.ToXml(query);
		}

		public static explicit operator CategoryQuery(string query)
		{
			return (CategoryQuery)CategoryQuery.SerializeHelper.FromXml(query, typeof(CategoryQuery));
		}
		
		#endregion		
	}

	[DataContract]
	[Serializable]
	abstract public partial class esCategory : esEntity
	{
		public esCategory()
		{

		}
		
		#region LoadByPrimaryKey
		public virtual bool LoadByPrimaryKey(System.Int32 categoryId)
		{
			if(this.es.Connection.SqlAccessType == esSqlAccessType.DynamicSQL)
				return LoadByPrimaryKeyDynamic(categoryId);
			else
				return LoadByPrimaryKeyStoredProcedure(categoryId);
		}

		public virtual bool LoadByPrimaryKey(esSqlAccessType sqlAccessType, System.Int32 categoryId)
		{
			if (sqlAccessType == esSqlAccessType.DynamicSQL)
				return LoadByPrimaryKeyDynamic(categoryId);
			else
				return LoadByPrimaryKeyStoredProcedure(categoryId);
		}

		private bool LoadByPrimaryKeyDynamic(System.Int32 categoryId)
		{
			CategoryQuery query = new CategoryQuery();
			query.Where(query.CategoryId == categoryId);
			return this.Load(query);
		}

		private bool LoadByPrimaryKeyStoredProcedure(System.Int32 categoryId)
		{
			esParameters parms = new esParameters();
			parms.Add("CategoryId", categoryId);
			return this.Load(esQueryType.StoredProcedure, this.es.spLoadByPrimaryKey, parms);
		}
		#endregion
		
		#region Properties
		
		
		
		/// <summary>
		/// Maps to DNNspot_LiveChat_Categories.PortalId
		/// </summary>
		[DataMember(EmitDefaultValue=false)]
		virtual public System.Int32? PortalId
		{
			get
			{
				return base.GetSystemInt32(CategoryMetadata.ColumnNames.PortalId);
			}
			
			set
			{
				if(base.SetSystemInt32(CategoryMetadata.ColumnNames.PortalId, value))
				{
					OnPropertyChanged(CategoryMetadata.PropertyNames.PortalId);
				}
			}
		}		
		
		/// <summary>
		/// Maps to DNNspot_LiveChat_Categories.CategoryId
		/// </summary>
		[DataMember(EmitDefaultValue=false)]
		virtual public System.Int32? CategoryId
		{
			get
			{
				return base.GetSystemInt32(CategoryMetadata.ColumnNames.CategoryId);
			}
			
			set
			{
				if(base.SetSystemInt32(CategoryMetadata.ColumnNames.CategoryId, value))
				{
					OnPropertyChanged(CategoryMetadata.PropertyNames.CategoryId);
				}
			}
		}		
		
		/// <summary>
		/// Maps to DNNspot_LiveChat_Categories.ParentCategoryId
		/// </summary>
		[DataMember(EmitDefaultValue=false)]
		virtual public System.Int32? ParentCategoryId
		{
			get
			{
				return base.GetSystemInt32(CategoryMetadata.ColumnNames.ParentCategoryId);
			}
			
			set
			{
				if(base.SetSystemInt32(CategoryMetadata.ColumnNames.ParentCategoryId, value))
				{
					this._UpToCategoryByParentCategoryId = null;
					this.OnPropertyChanged("UpToCategoryByParentCategoryId");
					OnPropertyChanged(CategoryMetadata.PropertyNames.ParentCategoryId);
				}
			}
		}		
		
		/// <summary>
		/// Maps to DNNspot_LiveChat_Categories.Name
		/// </summary>
		[DataMember(EmitDefaultValue=false)]
		virtual public System.String Name
		{
			get
			{
				return base.GetSystemString(CategoryMetadata.ColumnNames.Name);
			}
			
			set
			{
				if(base.SetSystemString(CategoryMetadata.ColumnNames.Name, value))
				{
					OnPropertyChanged(CategoryMetadata.PropertyNames.Name);
				}
			}
		}		
		
		/// <summary>
		/// Maps to DNNspot_LiveChat_Categories.CreatedDate
		/// </summary>
		[DataMember(EmitDefaultValue=false)]
		virtual public System.DateTime? CreatedDate
		{
			get
			{
				return base.GetSystemDateTime(CategoryMetadata.ColumnNames.CreatedDate);
			}
			
			set
			{
				if(base.SetSystemDateTime(CategoryMetadata.ColumnNames.CreatedDate, value))
				{
					OnPropertyChanged(CategoryMetadata.PropertyNames.CreatedDate);
				}
			}
		}		
		
		/// <summary>
		/// Maps to DNNspot_LiveChat_Categories.ModifiedDate
		/// </summary>
		[DataMember(EmitDefaultValue=false)]
		virtual public System.DateTime? ModifiedDate
		{
			get
			{
				return base.GetSystemDateTime(CategoryMetadata.ColumnNames.ModifiedDate);
			}
			
			set
			{
				if(base.SetSystemDateTime(CategoryMetadata.ColumnNames.ModifiedDate, value))
				{
					OnPropertyChanged(CategoryMetadata.PropertyNames.ModifiedDate);
				}
			}
		}		
		
		[CLSCompliant(false)]
		internal protected Category _UpToCategoryByParentCategoryId;
		#endregion	

		#region .str() Properties
		
		public override void SetProperties(IDictionary values)
		{
			foreach (string propertyName in values.Keys)
			{
				this.SetProperty(propertyName, values[propertyName]);
			}
		}
		
		public override void SetProperty(string name, object value)
		{
			esColumnMetadata col = this.Meta.Columns.FindByPropertyName(name);
			if (col != null)
			{
				if(value == null || value is System.String)
				{				
					// Use the strongly typed property
					switch (name)
					{							
						case "PortalId": this.str().PortalId = (string)value; break;							
						case "CategoryId": this.str().CategoryId = (string)value; break;							
						case "ParentCategoryId": this.str().ParentCategoryId = (string)value; break;							
						case "Name": this.str().Name = (string)value; break;							
						case "CreatedDate": this.str().CreatedDate = (string)value; break;							
						case "ModifiedDate": this.str().ModifiedDate = (string)value; break;
					}
				}
				else
				{
					switch (name)
					{	
						case "PortalId":
						
							if (value == null || value is System.Int32)
								this.PortalId = (System.Int32?)value;
								OnPropertyChanged(CategoryMetadata.PropertyNames.PortalId);
							break;
						
						case "CategoryId":
						
							if (value == null || value is System.Int32)
								this.CategoryId = (System.Int32?)value;
								OnPropertyChanged(CategoryMetadata.PropertyNames.CategoryId);
							break;
						
						case "ParentCategoryId":
						
							if (value == null || value is System.Int32)
								this.ParentCategoryId = (System.Int32?)value;
								OnPropertyChanged(CategoryMetadata.PropertyNames.ParentCategoryId);
							break;
						
						case "CreatedDate":
						
							if (value == null || value is System.DateTime)
								this.CreatedDate = (System.DateTime?)value;
								OnPropertyChanged(CategoryMetadata.PropertyNames.CreatedDate);
							break;
						
						case "ModifiedDate":
						
							if (value == null || value is System.DateTime)
								this.ModifiedDate = (System.DateTime?)value;
								OnPropertyChanged(CategoryMetadata.PropertyNames.ModifiedDate);
							break;
					

						default:
							break;
					}
				}
			}
            else if (this.ContainsColumn(name))
            {
                this.SetColumn(name, value);
            }
			else
			{
				throw new Exception("SetProperty Error: '" + name + "' not found");
			}
		}		

		public esStrings str()
		{
			if (esstrings == null)
			{
				esstrings = new esStrings(this);
			}
			return esstrings;
		}

		sealed public class esStrings
		{
			public esStrings(esCategory entity)
			{
				this.entity = entity;
			}
			
	
			public System.String PortalId
			{
				get
				{
					System.Int32? data = entity.PortalId;
					return (data == null) ? String.Empty : Convert.ToString(data);
				}

				set
				{
					if (value == null || value.Length == 0) entity.PortalId = null;
					else entity.PortalId = Convert.ToInt32(value);
				}
			}
				
			public System.String CategoryId
			{
				get
				{
					System.Int32? data = entity.CategoryId;
					return (data == null) ? String.Empty : Convert.ToString(data);
				}

				set
				{
					if (value == null || value.Length == 0) entity.CategoryId = null;
					else entity.CategoryId = Convert.ToInt32(value);
				}
			}
				
			public System.String ParentCategoryId
			{
				get
				{
					System.Int32? data = entity.ParentCategoryId;
					return (data == null) ? String.Empty : Convert.ToString(data);
				}

				set
				{
					if (value == null || value.Length == 0) entity.ParentCategoryId = null;
					else entity.ParentCategoryId = Convert.ToInt32(value);
				}
			}
				
			public System.String Name
			{
				get
				{
					System.String data = entity.Name;
					return (data == null) ? String.Empty : Convert.ToString(data);
				}

				set
				{
					if (value == null || value.Length == 0) entity.Name = null;
					else entity.Name = Convert.ToString(value);
				}
			}
				
			public System.String CreatedDate
			{
				get
				{
					System.DateTime? data = entity.CreatedDate;
					return (data == null) ? String.Empty : Convert.ToString(data);
				}

				set
				{
					if (value == null || value.Length == 0) entity.CreatedDate = null;
					else entity.CreatedDate = Convert.ToDateTime(value);
				}
			}
				
			public System.String ModifiedDate
			{
				get
				{
					System.DateTime? data = entity.ModifiedDate;
					return (data == null) ? String.Empty : Convert.ToString(data);
				}

				set
				{
					if (value == null || value.Length == 0) entity.ModifiedDate = null;
					else entity.ModifiedDate = Convert.ToDateTime(value);
				}
			}
			

			private esCategory entity;
		}
		
		[NonSerialized]
		private esStrings esstrings;		
		
		#endregion
		
		#region Housekeeping methods

		override protected IMetadata Meta
		{
			get
			{
				return CategoryMetadata.Meta();
			}
		}

		#endregion		
		
		#region Query Logic

		public CategoryQuery Query
		{
			get
			{
				if (this.query == null)
				{
					this.query = new CategoryQuery();
					InitQuery(this.query);
				}

				return this.query;
			}
		}

		public bool Load(CategoryQuery query)
		{
			this.query = query;
			InitQuery(this.query);
			return this.Query.Load();
		}
		
		protected void InitQuery(CategoryQuery query)
		{
			query.OnLoadDelegate = this.OnQueryLoaded;
			
			if (!query.es2.HasConnection)
			{
				query.es2.Connection = ((IEntity)this).Connection;
			}			
		}

		#endregion
		
        [IgnoreDataMember]
		private CategoryQuery query;		
	}



	[Serializable]
	abstract public partial class esCategoryCollection : esEntityCollection<Category>
	{
		#region Housekeeping methods
		override protected IMetadata Meta
		{
			get
			{
				return CategoryMetadata.Meta();
			}
		}

		protected override string GetCollectionName()
		{
			return "CategoryCollection";
		}

		#endregion		
		
		#region Query Logic

	#if (!WindowsCE)
		[BrowsableAttribute(false)]
	#endif
		public CategoryQuery Query
		{
			get
			{
				if (this.query == null)
				{
					this.query = new CategoryQuery();
					InitQuery(this.query);
				}

				return this.query;
			}
		}

		public bool Load(CategoryQuery query)
		{
			this.query = query;
			InitQuery(this.query);
			return Query.Load();
		}

		override protected esDynamicQuery GetDynamicQuery()
		{
			if (this.query == null)
			{
				this.query = new CategoryQuery();
				this.InitQuery(query);
			}
			return this.query;
		}

		protected void InitQuery(CategoryQuery query)
		{
			query.OnLoadDelegate = this.OnQueryLoaded;
			
			if (!query.es2.HasConnection)
			{
				query.es2.Connection = ((IEntityCollection)this).Connection;
			}			
		}

		protected override void HookupQuery(esDynamicQuery query)
		{
			this.InitQuery((CategoryQuery)query);
		}

		#endregion
		
		private CategoryQuery query;
	}



	[Serializable]
	abstract public partial class esCategoryQuery : esDynamicQuery
	{
		override protected IMetadata Meta
		{
			get
			{
				return CategoryMetadata.Meta();
			}
		}	
		
		#region QueryItemFromName
		
        protected override esQueryItem QueryItemFromName(string name)
        {
            switch (name)
            {
				case "PortalId": return this.PortalId;
				case "CategoryId": return this.CategoryId;
				case "ParentCategoryId": return this.ParentCategoryId;
				case "Name": return this.Name;
				case "CreatedDate": return this.CreatedDate;
				case "ModifiedDate": return this.ModifiedDate;

                default: return null;
            }
        }		
		
		#endregion
		
		#region esQueryItems

		public esQueryItem PortalId
		{
			get { return new esQueryItem(this, CategoryMetadata.ColumnNames.PortalId, esSystemType.Int32); }
		} 
		
		public esQueryItem CategoryId
		{
			get { return new esQueryItem(this, CategoryMetadata.ColumnNames.CategoryId, esSystemType.Int32); }
		} 
		
		public esQueryItem ParentCategoryId
		{
			get { return new esQueryItem(this, CategoryMetadata.ColumnNames.ParentCategoryId, esSystemType.Int32); }
		} 
		
		public esQueryItem Name
		{
			get { return new esQueryItem(this, CategoryMetadata.ColumnNames.Name, esSystemType.String); }
		} 
		
		public esQueryItem CreatedDate
		{
			get { return new esQueryItem(this, CategoryMetadata.ColumnNames.CreatedDate, esSystemType.DateTime); }
		} 
		
		public esQueryItem ModifiedDate
		{
			get { return new esQueryItem(this, CategoryMetadata.ColumnNames.ModifiedDate, esSystemType.DateTime); }
		} 
		
		#endregion
		
	}


	
	public partial class Category : esCategory
	{

		#region CategoryCollectionByParentCategoryId - Zero To Many
		
		static public esPrefetchMap Prefetch_CategoryCollectionByParentCategoryId
		{
			get
			{
				esPrefetchMap map = new esPrefetchMap();
				map.PrefetchDelegate = DNNspot.LiveChat.DataModel.Category.CategoryCollectionByParentCategoryId_Delegate;
				map.PropertyName = "CategoryCollectionByParentCategoryId";
				map.MyColumnName = "CategoryId";
				map.ParentColumnName = "ParentCategoryId";
				map.IsMultiPartKey = false;
				return map;
			}
		}		
		
		static private void CategoryCollectionByParentCategoryId_Delegate(esPrefetchParameters data)
		{
			CategoryQuery parent = new CategoryQuery(data.NextAlias());

			CategoryQuery me = data.You != null ? data.You as CategoryQuery : new CategoryQuery(data.NextAlias());

			if (data.Root == null)
			{
				data.Root = me;
			}
			
			data.Root.InnerJoin(parent).On(parent.ParentCategoryId == me.CategoryId);

			data.You = parent;
		}			
		
		/// <summary>
		/// Zero to Many
		/// Foreign Key Name - FK_DNNspot_LiveChat_Categories_DNNspot_LiveChat_Categories
		/// </summary>

		[XmlIgnore]
		public CategoryCollection CategoryCollectionByParentCategoryId
		{
			get
			{
				if(this._CategoryCollectionByParentCategoryId == null)
				{
					this._CategoryCollectionByParentCategoryId = new CategoryCollection();
					this._CategoryCollectionByParentCategoryId.es.Connection.Name = this.es.Connection.Name;
					this.SetPostSave("CategoryCollectionByParentCategoryId", this._CategoryCollectionByParentCategoryId);
				
					if (this.CategoryId != null)
					{
						if (!this.es.IsLazyLoadDisabled)
						{
							this._CategoryCollectionByParentCategoryId.Query.Where(this._CategoryCollectionByParentCategoryId.Query.ParentCategoryId == this.CategoryId);
							this._CategoryCollectionByParentCategoryId.Query.Load();
						}

						// Auto-hookup Foreign Keys
						this._CategoryCollectionByParentCategoryId.fks.Add(CategoryMetadata.ColumnNames.ParentCategoryId, this.CategoryId);
					}
				}

				return this._CategoryCollectionByParentCategoryId;
			}
			
			set 
			{ 
				if (value != null) throw new Exception("'value' Must be null"); 
			 
				if (this._CategoryCollectionByParentCategoryId != null) 
				{ 
					this.RemovePostSave("CategoryCollectionByParentCategoryId"); 
					this._CategoryCollectionByParentCategoryId = null;
					
				} 
			} 			
		}
			
		
		private CategoryCollection _CategoryCollectionByParentCategoryId;
		#endregion

				
		#region UpToCategoryByParentCategoryId - Many To One
		/// <summary>
		/// Many to One
		/// Foreign Key Name - FK_DNNspot_LiveChat_Categories_DNNspot_LiveChat_Categories
		/// </summary>

		[XmlIgnore]
					
		public Category UpToCategoryByParentCategoryId
		{
			get
			{
				if (this.es.IsLazyLoadDisabled) return null;
				
				if(this._UpToCategoryByParentCategoryId == null && ParentCategoryId != null)
				{
					this._UpToCategoryByParentCategoryId = new Category();
					this._UpToCategoryByParentCategoryId.es.Connection.Name = this.es.Connection.Name;
					this.SetPreSave("UpToCategoryByParentCategoryId", this._UpToCategoryByParentCategoryId);
					this._UpToCategoryByParentCategoryId.Query.Where(this._UpToCategoryByParentCategoryId.Query.CategoryId == this.ParentCategoryId);
					this._UpToCategoryByParentCategoryId.Query.Load();
				}	
				return this._UpToCategoryByParentCategoryId;
			}
			
			set
			{
				this.RemovePreSave("UpToCategoryByParentCategoryId");
				

				if(value == null)
				{
					this.ParentCategoryId = null;
					this._UpToCategoryByParentCategoryId = null;
				}
				else
				{
					this.ParentCategoryId = value.CategoryId;
					this._UpToCategoryByParentCategoryId = value;
					this.SetPreSave("UpToCategoryByParentCategoryId", this._UpToCategoryByParentCategoryId);
				}
				
			}
		}
		#endregion
		

		#region SessionCollectionByCategoryId - Zero To Many
		
		static public esPrefetchMap Prefetch_SessionCollectionByCategoryId
		{
			get
			{
				esPrefetchMap map = new esPrefetchMap();
				map.PrefetchDelegate = DNNspot.LiveChat.DataModel.Category.SessionCollectionByCategoryId_Delegate;
				map.PropertyName = "SessionCollectionByCategoryId";
				map.MyColumnName = "CategoryId";
				map.ParentColumnName = "CategoryId";
				map.IsMultiPartKey = false;
				return map;
			}
		}		
		
		static private void SessionCollectionByCategoryId_Delegate(esPrefetchParameters data)
		{
			CategoryQuery parent = new CategoryQuery(data.NextAlias());

			SessionQuery me = data.You != null ? data.You as SessionQuery : new SessionQuery(data.NextAlias());

			if (data.Root == null)
			{
				data.Root = me;
			}
			
			data.Root.InnerJoin(parent).On(parent.CategoryId == me.CategoryId);

			data.You = parent;
		}			
		
		/// <summary>
		/// Zero to Many
		/// Foreign Key Name - FK_DNNspot_LiveChat_Sessions_DNNspot_LiveChat_Categories
		/// </summary>

		[XmlIgnore]
		public SessionCollection SessionCollectionByCategoryId
		{
			get
			{
				if(this._SessionCollectionByCategoryId == null)
				{
					this._SessionCollectionByCategoryId = new SessionCollection();
					this._SessionCollectionByCategoryId.es.Connection.Name = this.es.Connection.Name;
					this.SetPostSave("SessionCollectionByCategoryId", this._SessionCollectionByCategoryId);
				
					if (this.CategoryId != null)
					{
						if (!this.es.IsLazyLoadDisabled)
						{
							this._SessionCollectionByCategoryId.Query.Where(this._SessionCollectionByCategoryId.Query.CategoryId == this.CategoryId);
							this._SessionCollectionByCategoryId.Query.Load();
						}

						// Auto-hookup Foreign Keys
						this._SessionCollectionByCategoryId.fks.Add(SessionMetadata.ColumnNames.CategoryId, this.CategoryId);
					}
				}

				return this._SessionCollectionByCategoryId;
			}
			
			set 
			{ 
				if (value != null) throw new Exception("'value' Must be null"); 
			 
				if (this._SessionCollectionByCategoryId != null) 
				{ 
					this.RemovePostSave("SessionCollectionByCategoryId"); 
					this._SessionCollectionByCategoryId = null;
					
				} 
			} 			
		}
			
		
		private SessionCollection _SessionCollectionByCategoryId;
		#endregion

		
		protected override esEntityCollectionBase CreateCollectionForPrefetch(string name)
		{
			esEntityCollectionBase coll = null;

			switch (name)
			{
				case "CategoryCollectionByParentCategoryId":
					coll = this.CategoryCollectionByParentCategoryId;
					break;
				case "SessionCollectionByCategoryId":
					coll = this.SessionCollectionByCategoryId;
					break;	
			}

			return coll;
		}		
		/// <summary>
		/// Used internally by the entity's hierarchical properties.
		/// </summary>
		protected override List<esPropertyDescriptor> GetHierarchicalProperties()
		{
			List<esPropertyDescriptor> props = new List<esPropertyDescriptor>();
			
			props.Add(new esPropertyDescriptor(this, "CategoryCollectionByParentCategoryId", typeof(CategoryCollection), new Category()));
			props.Add(new esPropertyDescriptor(this, "SessionCollectionByCategoryId", typeof(SessionCollection), new Session()));
		
			return props;
		}
		/// <summary>
		/// Used internally for retrieving AutoIncrementing keys
		/// during hierarchical PreSave.
		/// </summary>
		protected override void ApplyPreSaveKeys()
		{
			if(!this.es.IsDeleted && this._UpToCategoryByParentCategoryId != null)
			{
				this.ParentCategoryId = this._UpToCategoryByParentCategoryId.CategoryId;
			}
		}
		
		/// <summary>
		/// Called by ApplyPostSaveKeys 
		/// </summary>
		/// <param name="coll">The collection to enumerate over</param>
		/// <param name="key">"The column name</param>
		/// <param name="value">The column value</param>
		private void Apply(esEntityCollectionBase coll, string key, object value)
		{
			foreach (esEntity obj in coll)
			{
				if (obj.es.IsAdded)
				{
					obj.SetProperty(key, value);
				}
			}
		}
		
		/// <summary>
		/// Used internally for retrieving AutoIncrementing keys
		/// during hierarchical PostSave.
		/// </summary>
		protected override void ApplyPostSaveKeys()
		{
			if(this._CategoryCollectionByParentCategoryId != null)
			{
				Apply(this._CategoryCollectionByParentCategoryId, "ParentCategoryId", this.CategoryId);
			}
			if(this._SessionCollectionByCategoryId != null)
			{
				Apply(this._SessionCollectionByCategoryId, "CategoryId", this.CategoryId);
			}
		}
		
	}
	



	[Serializable]
	public partial class CategoryMetadata : esMetadata, IMetadata
	{
		#region Protected Constructor
		protected CategoryMetadata()
		{
			m_columns = new esColumnMetadataCollection();
			esColumnMetadata c;

			c = new esColumnMetadata(CategoryMetadata.ColumnNames.PortalId, 0, typeof(System.Int32), esSystemType.Int32);
			c.PropertyName = CategoryMetadata.PropertyNames.PortalId;
			c.NumericPrecision = 10;
			m_columns.Add(c);
				
			c = new esColumnMetadata(CategoryMetadata.ColumnNames.CategoryId, 1, typeof(System.Int32), esSystemType.Int32);
			c.PropertyName = CategoryMetadata.PropertyNames.CategoryId;
			c.IsInPrimaryKey = true;
			c.IsAutoIncrement = true;
			c.NumericPrecision = 10;
			m_columns.Add(c);
				
			c = new esColumnMetadata(CategoryMetadata.ColumnNames.ParentCategoryId, 2, typeof(System.Int32), esSystemType.Int32);
			c.PropertyName = CategoryMetadata.PropertyNames.ParentCategoryId;
			c.NumericPrecision = 10;
			c.IsNullable = true;
			m_columns.Add(c);
				
			c = new esColumnMetadata(CategoryMetadata.ColumnNames.Name, 3, typeof(System.String), esSystemType.String);
			c.PropertyName = CategoryMetadata.PropertyNames.Name;
			c.CharacterMaxLength = 50;
			m_columns.Add(c);
				
			c = new esColumnMetadata(CategoryMetadata.ColumnNames.CreatedDate, 4, typeof(System.DateTime), esSystemType.DateTime);
			c.PropertyName = CategoryMetadata.PropertyNames.CreatedDate;
			c.HasDefault = true;
			c.Default = @"(getdate())";
			m_columns.Add(c);
				
			c = new esColumnMetadata(CategoryMetadata.ColumnNames.ModifiedDate, 5, typeof(System.DateTime), esSystemType.DateTime);
			c.PropertyName = CategoryMetadata.PropertyNames.ModifiedDate;
			c.HasDefault = true;
			c.Default = @"(getdate())";
			m_columns.Add(c);
				
		}
		#endregion	
	
		static public CategoryMetadata Meta()
		{
			return meta;
		}	
		
		public Guid DataID
		{
			get { return base.m_dataID; }
		}	
		
		public bool MultiProviderMode
		{
			get { return false; }
		}		

		public esColumnMetadataCollection Columns
		{
			get	{ return base.m_columns; }
		}
		
		#region ColumnNames
		public class ColumnNames
		{ 
			 public const string PortalId = "PortalId";
			 public const string CategoryId = "CategoryId";
			 public const string ParentCategoryId = "ParentCategoryId";
			 public const string Name = "Name";
			 public const string CreatedDate = "CreatedDate";
			 public const string ModifiedDate = "ModifiedDate";
		}
		#endregion	
		
		#region PropertyNames
		public class PropertyNames
		{ 
			 public const string PortalId = "PortalId";
			 public const string CategoryId = "CategoryId";
			 public const string ParentCategoryId = "ParentCategoryId";
			 public const string Name = "Name";
			 public const string CreatedDate = "CreatedDate";
			 public const string ModifiedDate = "ModifiedDate";
		}
		#endregion	

		public esProviderSpecificMetadata GetProviderMetadata(string mapName)
		{
			MapToMeta mapMethod = mapDelegates[mapName];

			if (mapMethod != null)
				return mapMethod(mapName);
			else
				return null;
		}
		
		#region MAP esDefault
		
		static private int RegisterDelegateesDefault()
		{
			// This is only executed once per the life of the application
			lock (typeof(CategoryMetadata))
			{
				if(CategoryMetadata.mapDelegates == null)
				{
					CategoryMetadata.mapDelegates = new Dictionary<string,MapToMeta>();
				}
				
				if (CategoryMetadata.meta == null)
				{
					CategoryMetadata.meta = new CategoryMetadata();
				}
				
				MapToMeta mapMethod = new MapToMeta(meta.esDefault);
				mapDelegates.Add("esDefault", mapMethod);
				mapMethod("esDefault");
			}
			return 0;
		}			

		private esProviderSpecificMetadata esDefault(string mapName)
		{
			if(!m_providerMetadataMaps.ContainsKey(mapName))
			{
				esProviderSpecificMetadata meta = new esProviderSpecificMetadata();			


				meta.AddTypeMap("PortalId", new esTypeMap("int", "System.Int32"));
				meta.AddTypeMap("CategoryId", new esTypeMap("int", "System.Int32"));
				meta.AddTypeMap("ParentCategoryId", new esTypeMap("int", "System.Int32"));
				meta.AddTypeMap("Name", new esTypeMap("nvarchar", "System.String"));
				meta.AddTypeMap("CreatedDate", new esTypeMap("datetime", "System.DateTime"));
				meta.AddTypeMap("ModifiedDate", new esTypeMap("datetime", "System.DateTime"));			
				
				
				
				meta.Source = "DNNspot_LiveChat_Categories";
				meta.Destination = "DNNspot_LiveChat_Categories";
				
				meta.spInsert = "proc_DNNspot_LiveChat_CategoriesInsert";				
				meta.spUpdate = "proc_DNNspot_LiveChat_CategoriesUpdate";		
				meta.spDelete = "proc_DNNspot_LiveChat_CategoriesDelete";
				meta.spLoadAll = "proc_DNNspot_LiveChat_CategoriesLoadAll";
				meta.spLoadByPrimaryKey = "proc_DNNspot_LiveChat_CategoriesLoadByPrimaryKey";
				
				this.m_providerMetadataMaps["esDefault"] = meta;
			}
			
			return this.m_providerMetadataMaps["esDefault"];
		}

		#endregion

		static private CategoryMetadata meta;
		static protected Dictionary<string, MapToMeta> mapDelegates;
		static private int _esDefault = RegisterDelegateesDefault();
	}
}
